//
//  MLWTipsICookOtherHeaderView.m
//  KITCHEN_STORIES
//
//  Created by 孟令通 on 16/6/14.
//  Copyright © 2016年 MLW. All rights reserved.
//

#import "MLWTipsICookOtherHeaderView.h"

#import "MLWTipsICookOtherSuitableModel.h"

#import "MLWBaseView.h"

@implementation MLWTipsICookOtherHeaderView

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithReuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.topLine = [[UILabel alloc] init];
        
        self.topLine.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1.00];
        
        [self.contentView addSubview:_topLine];
        [_topLine release];
        
        
        self.title = [[UILabel alloc] init];
        [self.title setFont:[UIFont systemFontOfSize:14]];
        self.title.textAlignment = 1;
        self.title.backgroundColor = [UIColor whiteColor];
        
        [self.contentView addSubview:_title];
        [_title release];
        
    }
    
    return self;
    
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.topLine makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.equalTo(ScreenWidth);
        
        make.height.equalTo(10);
        
        make.top.equalTo(self.contentView).offset(0);
        
        make.left.equalTo(self.contentView).offset(0);
        
    }];
    
    [self.title makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(0);
        
        make.right.equalTo(self.contentView).offset(0);
        
        make.top.equalTo(self.topLine.bottom).offset(0);
        
        make.bottom.equalTo(self.contentView).offset(0);
        
    }];
    
}

-(void)setModel:(MLWTipsICookOtherModel *)model
{
    if (_model != model) {
        
        [_model release];
        
        _model = [model retain];
        
        NSString *string = [NSString string];

        if (self.section == 0) {
            
            string = [NSString stringWithFormat:@"与%@搭配相宜的食材", _model.material_name];
            
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:string];
            
            [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.36 green:0.72 blue:0.33 alpha:1.00] range:NSMakeRange(_model.material_name.length + 3, 2)];
            
            self.title.attributedText = str;
            
        }
        if (self.section == 1) {
            
            string = [NSString stringWithFormat:@"与%@搭配相克的食材", _model.material_name];
            
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:string];
            
            [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:1.00 green:0.00 blue:0.00 alpha:1.00] range:NSMakeRange(_model.material_name.length + 3, 2)];
            
            self.title.attributedText = str;
        }
        
        
        
    }
}

@end
